package Servlet.Order;

import BaseClass.OrderInfo;
import DataBase.DataBase;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class GetOrderInfoServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession HS = req.getSession();
        if (HS.getAttribute("username") == null) resp.sendRedirect("User/Login.jsp");
        else {
            String username = HS.getAttribute("username").toString();
            List<OrderInfo> orderInfo = DataBase.getOrderInfo(username);
            HS.setAttribute("OrderInfo",orderInfo);
            resp.sendRedirect("Order/MyOrder.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
